package controllers.administrator;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.OwnershipHistoryService;
import services.PaintingService;
import controllers.AbstractController;
import domain.OwnershipHistory;
import domain.Painting;


@Controller
@RequestMapping("/ownershipHistory/administrator")
public class OwnershipHistoryAdministratorController extends AbstractController {

	//Services
			@Autowired
			private OwnershipHistoryService ownershipHistoryService;
			@Autowired
			private PaintingService paintingService;
			
			//Constructor
			public OwnershipHistoryAdministratorController(){
				super();
			}
			
			// Listing methods
			@RequestMapping(value = "/list", method = RequestMethod.GET)
			public ModelAndView list(@RequestParam int paintingId) {
				ModelAndView result;
				Painting painting;
				Collection<OwnershipHistory> ownershipHistories;

				painting = paintingService.findOne(paintingId);
				ownershipHistories = ownershipHistoryService.findByPainting(painting);

				result = new ModelAndView("ownershipHistory/list");
				result.addObject("requestURI", "ownershipHistories/administrator/list.do");
				result.addObject("ownershipHistories", ownershipHistories);
				result.addObject("backURI", "/welcome/index.do");
				return result;
			}
}
